/*
 * Copyright (c) 2021, Peter Abeles. All Rights Reserved.
 *
 * This file is part of BoofCV (http://boofcv.org).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package boofcv.alg.template;

import boofcv.BoofTesting;
import boofcv.alg.misc.GImageMiscOps;
import boofcv.core.image.GeneralizedImageOps;
import boofcv.struct.image.ImageGray;
import boofcv.testing.BoofStandardJUnit;
import org.junit.jupiter.api.Test;

/**
 * @author Peter Abeles
 */
abstract class GeneralTemplateIntensityImage_MT <T extends ImageGray<T>> extends BoofStandardJUnit {

	// image and template being matched
	T image;
	T template;
	T mask;

	TemplateIntensityImage<T> alg_ST;
	TemplateIntensityImage_MT<T> alg_MT;

	protected GeneralTemplateIntensityImage_MT(TemplateIntensityImage.EvaluatorMethod<T> method, Class<T> imageType) {
		this.alg_ST = new TemplateIntensityImage<>(method);
		this.alg_MT = new TemplateIntensityImage_MT<>(method);

		image = GeneralizedImageOps.createSingleBand(imageType, 60, 70);
		template = GeneralizedImageOps.createSingleBand(imageType, 5, 8);
		mask = GeneralizedImageOps.createSingleBand(imageType, 5, 8);

		GImageMiscOps.fillUniform(template, rand, 50, 60);
	}

	@Test
	void compare_no_mask() {
		alg_ST.setInputImage(image);
		alg_ST.process(template);

		alg_MT.setInputImage(image);
		alg_MT.process(template);

		BoofTesting.assertEquals(alg_ST.getIntensity(),alg_MT.getIntensity(),1e-4);
	}


	@Test
	void compare_mask() {
		alg_ST.setInputImage(image);
		alg_ST.process(template,mask);

		alg_MT.setInputImage(image);
		alg_MT.process(template,mask);

		BoofTesting.assertEquals(alg_ST.getIntensity(),alg_MT.getIntensity(),1e-4);
	}

}
